package app.sys.data.comm;

import lombok.Data;

@Data
public class ApiResult<T> {
    private String status;
    private String msg;
    private T data;

    public static ApiResult of(final String code, final String message, final Object data) {
        ApiResult<Object> apiResult = new ApiResult<>();
        apiResult.setStatus(code);
        apiResult.setData(data);
        apiResult.setMsg(message);
        return apiResult;
    }

    public static ApiResult of(final ApiCode apiCode) {
        ApiResult<Object> apiResult = new ApiResult<>();
        apiResult.setStatus(apiCode.getStatus());
        apiResult.setMsg(apiCode.getMsg());
        return apiResult;
    }

    public static ApiResult of(final ApiCode apiCode, final Object data) {
        ApiResult<Object> apiResult = new ApiResult<>();
        apiResult.setStatus(apiCode.getStatus());
        apiResult.setMsg(apiCode.getMsg());
        apiResult.setData(data);
        return apiResult;
    }

    public static ApiResult of(final String code, final Object data) {
        ApiResult<Object> apiResult = new ApiResult<>();
        apiResult.setStatus(code);
        apiResult.setData(data);
        return apiResult;
    }

    public static ApiResult of(final String code, final String msg) {
        ApiResult<Object> apiResult = new ApiResult<>();
        apiResult.setStatus(code);
        apiResult.setMsg(msg);
        return apiResult;
    }

    public static ApiResult of(final Object data) {
        ApiResult apiResult = of(ApiCode.SUCCESS);
        apiResult.setData(data);
        return apiResult;
    }


    public ApiResult() {
    }
}
